Ext.define('OrderConvert.view.convert.ConvertAddFormWinController', {
    extend: 'Ext.app.ViewController',
    alias: 'controller.convert-convertaddformwin',

    submit : function (btn) {
        var win = btn.up("window");
        var form = win.down("form");
        var tree = form.down("treepanel");
        var checked = tree.getChecked();
        var deps = [];
        if(checked != null && checked.length > 0){
            for(var i =0; i < checked.length; i++){
                var item = checked[i];
                var id = item.get("id");
                deps.push(id);
            }
        }
        var convertGridController = Ext.create("OrderConvert.view.convert.ConvertGridController");
        if(form.isValid()) {
            form.submit({
                url : OrderConvertUrl.constant.serverUrl + 'convert/add',
                waitMsg: '文件上传中...',
                params : {
                    deps : deps.join()
                },
                success: function(form, action) {
                    win.close();
                    convertGridController.reload();
                    // Ext.Msg.alert('Success',"success");
                },
                failure: function(form, action) {
                    console.log(action);
                    win.close();
                    convertGridController.reload();
                    // Ext.Msg.alert('Failed', "failure");
                }
            });
        }
    },

    update : function (btn) {
        var win = btn.up("window");
        var form = win.down("form");
        var tree = form.down("treepanel");
        var checked = tree.getChecked();
        var deps = [];
        if(checked != null && checked.length > 0){
            for(var i =0; i < checked.length; i++){
                var item = checked[i];
                var id = item.get("id");
                deps.push(id);
            }
        }
        var convertGridController = Ext.create("OrderConvert.view.convert.ConvertGridController");
        if(form.isValid()) {
            form.submit({
                url : OrderConvertUrl.constant.serverUrl + 'convert/edit',
                waitMsg: '文件上传中...',
                params : {
                    deps : deps.join()
                },
                success: function(form, action) {
                    win.close();
                    convertGridController.reload();
                    // Ext.Msg.alert('Success',"success");
                },
                failure: function(form, action) {
                    console.log(action);
                    win.close();
                    convertGridController.reload();
                }
            });
        }
    },
    
    close : function (btn) {
        var win = btn.up("window");
        win.close();
    }
    
});
